import React, { useEffect, useState,} from 'react'
import { InfiniteScroll } from 'antd-mobile'
import { useSearchParams} from 'react-router-dom'
import request from '../../api/request'

function Index() {
    let [list,setlist]=useState([])
    const [selQuery] = useSearchParams();
    let [page,setpage]=useState(1)
    let [hasMore,setHasMore]=useState(true)
  //  let nav=useNavigate()
    let getData=async()=>{
      const data = Object.fromEntries(selQuery);
        let res=await request.post('/api/trip/train',{...data,page})
        console.log('res11',res)
        setlist([...list,...res.data.data])
        setpage(page+1)
        if(res.data.data.length===0){
          setHasMore(false)
        }
    }
    useEffect(()=>{
      getData()
    },[])
  return (
    <div>
      <div>
      {
        list&&list.map((item,index)=>(
          <div key={index}>
                 <span>发车 {item.startTime}</span>
              <span>{item.startStation}</span>
              <span>{item.trainNo}</span>
              <span>¥{item.ssoftSeat.price}</span>

              <span>到达 {item.endTime}</span>
              <span>{item.endStation}</span>
              <span>耗时 {item.timeTaken}</span>
              <span>
                二等座：{item.ssoftSeat.ticketNum}
                {typeof item.ssoftSeat.ticketNum === "number" ? "张" : ""}
              </span>
            </div>
        ))
      }
      </div>
    
      <InfiniteScroll loadMore={getData} hasMore={hasMore} />
    </div>
  )
}

export default Index
